#ifndef THREAD_POOL_H
#define THREAD_POOL_H
#include <custom_head.h>
#include "intTable.h"
#include "l8w8jwt/decode.h"
#include "l8w8jwt/encode.h"
#include "mysqlClient.h"
#include "stack.h"
#include "taskQueue.h"
#include "tcp.h"
#include "threadArr.h"
#include "userTable.h"
#include "util.h"
#include "wheelTimer.h"
#include "toml.h"
#include "vfs.h"
#include "longCmdServer.h"

#define LOG_CLIENT_EVENT(level, client, format, ...) \
    do { \
        if (client.netfd != -1) { \
            syslog(level, "[%s] %s:%d (User: %s) - " format, \
                   strftime_local(), \
                   inet_ntoa(client.addr.sin_addr), \
                   ntohs(client.addr.sin_port), \
                   client.user_name[0] ? client.user_name : "Anonymous", \
                   ##__VA_ARGS__); \
        } \
    } while(0)


typedef struct threadPool_s {
  threadArr t_arr;
  taskQueue queue;
  userTable *user_map;
  MYSQL **mysql;
  pthread_mutex_t mutex;
  pthread_cond_t cond;
  int is_close;
} threadPool;

typedef struct Para_s {
  int netfd;
  int epfd;
  char **path;
  threadPool *pool;
  conn_info *client;
  int *index;
} Para;

int epoll_add(int epfd, int fd);
int epoll_del(int epfd, int fd);

int threadPool_init(threadPool *pool, int work_num);
int threadPool_make_worker(threadPool *pool);
void *worker(void *arg);

int analyze(char *jwt, char *cmd, Task *t, int netfd, int epfd,
            threadPool *pool, conn_info *client, int *index);
void free_para(Para *para);
char* strftime_local();
#endif
